package com.allenkerr.queue3;

import java.util.function.Consumer;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import com.allenkerr.queue1.OrderIdConsumer;
import com.allenkerr.queue1.RedisQueue1;

import static com.allenkerr.queue1.RedisTaskContainer.ORDER_ID_QUEUE;

/**
 * @author 小柯
 * @date 2018/3/20
 */
//@Component
public class QueueConsumer {

  @Autowired
  private RedisTemplate redisTemplate;
  @Autowired
  private RedisQueueListener redisQueueListener;

  private static final Logger logger = LoggerFactory.getLogger(QueueConsumer.class);

  private static final String REDIS_KEY = "user:queue1";

  /**
   * 启动后执行
   */
  @Bean
  public RedisQueue3<String> redisQueue() {
    logger.info("\n----------------------------------------");
    logger.info("QueueConsumer.redisQueue");
    logger.info("----------------------------------------\n");

    return new RedisQueue3<>(redisTemplate, REDIS_KEY, redisQueueListener);
  }

  /**
   * 关闭前执行
   */
  @PreDestroy
  public void doBeforeSystemShutdown() {
    logger.info("\n----------------------------------------");
    logger.info("QueueConsumer.doBeforeSystemShutdown");
    logger.info("----------------------------------------\n");
  }

}
